package com.han.interceptor;

import cn.hutool.core.util.StrUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

public class UserInfoInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1.获取请求头中的用户
        String userInfo = request.getHeader("user-info");
        // 2.判断是否为空，不为空，存入Usercontext
        if (StrUtil.isNotBlank(userInfo)) {


        }
        // 3.放行
        List list = new ArrayList();
        ReentrantLock reentrantLock = new ReentrantLock();
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception{

        // 清除用户
//        UserContext.removeUser();
    }
}
